{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import re\n",
    "import numpy as np\n",
    "import pandas as pd\n",
    "import matplotlib.pyplot as plt\n",
    "import matplotlib.dates as mdates\n",
    "from datetime import datetime\n",
    "from datetime import timedelta\n",
    "from matplotlib.ticker import MultipleLocator\n",
    "\n",
    "%matplotlib inline\n",
    "\n",
    "# re: https://www.cnblogs.com/tina-python/p/5508402.html"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'filename': 'RuleEngineLog.h', 'line': '44'}"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# test simple\n",
    "match = re.match(r'(?P<filename>[a-zA-Z0-9_\\.]*[^:]):(?P<line>\\d+)', 'RuleEngineLog.h:44')\n",
    "# match = re.match(r'(?P<function>[a-zA-Z0-9_]*)', 'clips_logd')\n",
    "match.groupdict()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 08-31 10:06:09.703  2882  3544 V homebrain: 2034181200 | RuleEngineLog.h:44 | clips_logd | 4 | (\"creaate rule context \" rul-cloud-virtualmode)\n",
    "hb_tag=r'homebrain'\n",
    "p_dt=r'(?P<datetime>\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}\\.\\d{3})'\n",
    "p_id1=r'(?P<pthreadid>\\d+)'\n",
    "p_id2=r'(?P<pid>\\d+)'\n",
    "p_id3=r'(?P<kernelpid>\\d+)'\n",
    "p_fnl=r'(?P<filename>[\\w\\.]*):(?P<line>\\d+)'\n",
    "p_func=r'(?P<function>\\w*)'\n",
    "p_loglevel=r'(?P<level>\\d{1})'\n",
    "p_message=r'(?P<message>.*[^$])'\n",
    "hb_re = re.compile(p_dt+'\\s+'+p_id1+'\\s+'+p_id2+' V '+hb_tag+': '+p_id3+' \\| '+p_fnl+' \\| '+p_func+' \\| '+p_loglevel+' \\| '+p_message+'$')\n",
    "\n",
    "# ret = hb_re.search('08-31 10:06:09.703  2882  3544 V homebrain: 2034181200 | RuleEngineLog.h:44 | clips_logd | 4 | (\\\"creaate rule context \\\" rul-cloud-virtualmode)')\n",
    "# print(ret.groupdict())\n",
    "\n",
    "loginfos = []\n",
    "\n",
    "def parser(file):\n",
    "    try:\n",
    "        with open(file) as f:\n",
    "            for line in f:\n",
    "                res = hb_re.search(line)\n",
    "                if res is None:\n",
    "                    continue\n",
    "                loginfos.append(res.groupdict())\n",
    "                # dt = datetime.strptime(gdict['datetime'], '%m-%d %H:%M:%S.%f').replace(year=2018)\n",
    "                \n",
    "    except IOError as e:\n",
    "        raise e"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>datetime</th>\n",
       "      <th>filename</th>\n",
       "      <th>function</th>\n",
       "      <th>kernelpid</th>\n",
       "      <th>level</th>\n",
       "      <th>line</th>\n",
       "      <th>message</th>\n",
       "      <th>pid</th>\n",
       "      <th>pthreadid</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>08-31 09:58:07.505</td>\n",
       "      <td>HBCloudManager.cpp</td>\n",
       "      <td>propertyControl</td>\n",
       "      <td>1970066512</td>\n",
       "      <td>4</td>\n",
       "      <td>33</td>\n",
       "      <td>(surper.virtual.device mode 10)\\n</td>\n",
       "      <td>3620</td>\n",
       "      <td>2882</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>08-31 09:58:07.505</td>\n",
       "      <td>lecloud_interface.cpp</td>\n",
       "      <td>lecloud_print</td>\n",
       "      <td>1970066512</td>\n",
       "      <td>4</td>\n",
       "      <td>24</td>\n",
       "      <td>[LE-INFO-31#09:58:06] send pkt op:503, seq:204...</td>\n",
       "      <td>3620</td>\n",
       "      <td>2882</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>08-31 09:58:07.509</td>\n",
       "      <td>lecloud_interface.cpp</td>\n",
       "      <td>lecloud_print</td>\n",
       "      <td>1970066512</td>\n",
       "      <td>4</td>\n",
       "      <td>24</td>\n",
       "      <td>[LE-INFO-31#09:58:06] recv pkt op:503, seq:204...</td>\n",
       "      <td>3620</td>\n",
       "      <td>2882</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>08-31 09:58:07.572</td>\n",
       "      <td>RuleEngineCore.cpp</td>\n",
       "      <td>assertRun</td>\n",
       "      <td>2034181200</td>\n",
       "      <td>3</td>\n",
       "      <td>114</td>\n",
       "      <td>((virtualmode 10))\\n</td>\n",
       "      <td>3544</td>\n",
       "      <td>2882</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>08-31 09:58:26.439</td>\n",
       "      <td>lecloud_interface.cpp</td>\n",
       "      <td>lecloud_print</td>\n",
       "      <td>1970066512</td>\n",
       "      <td>4</td>\n",
       "      <td>24</td>\n",
       "      <td>[LE-INFO-31#09:58:25] recv pkt op:504, seq:489...</td>\n",
       "      <td>3620</td>\n",
       "      <td>2882</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "             datetime               filename         function   kernelpid  \\\n",
       "0  08-31 09:58:07.505     HBCloudManager.cpp  propertyControl  1970066512   \n",
       "1  08-31 09:58:07.505  lecloud_interface.cpp    lecloud_print  1970066512   \n",
       "2  08-31 09:58:07.509  lecloud_interface.cpp    lecloud_print  1970066512   \n",
       "3  08-31 09:58:07.572     RuleEngineCore.cpp        assertRun  2034181200   \n",
       "4  08-31 09:58:26.439  lecloud_interface.cpp    lecloud_print  1970066512   \n",
       "\n",
       "  level line                                            message   pid  \\\n",
       "0     4   33                  (surper.virtual.device mode 10)\\n  3620   \n",
       "1     4   24  [LE-INFO-31#09:58:06] send pkt op:503, seq:204...  3620   \n",
       "2     4   24  [LE-INFO-31#09:58:06] recv pkt op:503, seq:204...  3620   \n",
       "3     3  114                               ((virtualmode 10))\\n  3544   \n",
       "4     4   24  [LE-INFO-31#09:58:25] recv pkt op:504, seq:489...  3620   \n",
       "\n",
       "  pthreadid  \n",
       "0      2882  \n",
       "1      2882  \n",
       "2      2882  \n",
       "3      2882  \n",
       "4      2882  "
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import os\n",
    "for f in os.listdir(os.getcwd()):\n",
    "    if 'logcat.log.' in f:\n",
    "        parser(f)\n",
    "log_df = pd.DataFrame(loginfos)\n",
    "log_df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "log_df.drop(columns=['kernelpid'], inplace=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "datetime     object\n",
      "filename     object\n",
      "function     object\n",
      "level         int64\n",
      "line          int64\n",
      "message      object\n",
      "pid           int64\n",
      "pthreadid     int64\n",
      "dtype: object\n"
     ]
    }
   ],
   "source": [
    "# type convert: object to int\n",
    "log_df['pid'] = log_df['pid'].astype(int)\n",
    "log_df['pthreadid'] = log_df['pthreadid'].astype(int)\n",
    "log_df['line'] = log_df['line'].astype(int)\n",
    "log_df['level'] = log_df['level'].astype(int)\n",
    "print(log_df.dtypes)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "# test object to datetime\n",
    "# datestrs = ['08-31 10:05:05.569','08-31 10:05:05.574']\n",
    "# test_df = pd.to_datetime(datestrs, format='%m-%d %H:%M:%S.%f')\n",
    "# print(type(test_df)) # datetimes.DatetimeIdex\n",
    "# test_df = test_df.map(lambda x: x.strftime('%m-%d %H:%M'))\n",
    "# print(type(test_df)) # base.Index\n",
    "# log_df['datetime'] = pd.to_datetime(log_df['datetime'], format='%m-%d %H:%M:%S.%f')\n",
    "# log_df['datetime'] = log_df['datetime'].apply(lambda x: datetime.strptime(x, '%m-%d %H:%M:%S.%f').replace(year=2018))\n",
    "# log_df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>filename</th>\n",
       "      <th>function</th>\n",
       "      <th>level</th>\n",
       "      <th>line</th>\n",
       "      <th>message</th>\n",
       "      <th>pid</th>\n",
       "      <th>pthreadid</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>datetime</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2018-08-31 09:54:58.201</th>\n",
       "      <td>lecloud_interface.cpp</td>\n",
       "      <td>lecloud_print</td>\n",
       "      <td>4</td>\n",
       "      <td>24</td>\n",
       "      <td>[LE-INFO-31#09:54:57] send pkt op:503, seq:193...</td>\n",
       "      <td>3620</td>\n",
       "      <td>2882</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-08-31 09:54:58.201</th>\n",
       "      <td>HBCloudManager.cpp</td>\n",
       "      <td>propertyControl</td>\n",
       "      <td>4</td>\n",
       "      <td>33</td>\n",
       "      <td>(surper.virtual.device mode 2)\\n</td>\n",
       "      <td>3620</td>\n",
       "      <td>2882</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-08-31 09:54:58.206</th>\n",
       "      <td>lecloud_interface.cpp</td>\n",
       "      <td>lecloud_print</td>\n",
       "      <td>4</td>\n",
       "      <td>24</td>\n",
       "      <td>[LE-INFO-31#09:54:57] recv pkt op:503, seq:193...</td>\n",
       "      <td>3620</td>\n",
       "      <td>2882</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-08-31 09:54:58.212</th>\n",
       "      <td>RuleEngineCore.cpp</td>\n",
       "      <td>assertRun</td>\n",
       "      <td>3</td>\n",
       "      <td>114</td>\n",
       "      <td>((virtualmode 2))\\n</td>\n",
       "      <td>3544</td>\n",
       "      <td>2882</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-08-31 09:54:58.214</th>\n",
       "      <td>RuleEngineService.cpp</td>\n",
       "      <td>callMessagePush</td>\n",
       "      <td>3</td>\n",
       "      <td>336</td>\n",
       "      <td>(1, 1, rul-001-autolight-service:2, success)\\n</td>\n",
       "      <td>3544</td>\n",
       "      <td>2882</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                      filename         function  level  line  \\\n",
       "datetime                                                                       \n",
       "2018-08-31 09:54:58.201  lecloud_interface.cpp    lecloud_print      4    24   \n",
       "2018-08-31 09:54:58.201     HBCloudManager.cpp  propertyControl      4    33   \n",
       "2018-08-31 09:54:58.206  lecloud_interface.cpp    lecloud_print      4    24   \n",
       "2018-08-31 09:54:58.212     RuleEngineCore.cpp        assertRun      3   114   \n",
       "2018-08-31 09:54:58.214  RuleEngineService.cpp  callMessagePush      3   336   \n",
       "\n",
       "                                                                   message  \\\n",
       "datetime                                                                     \n",
       "2018-08-31 09:54:58.201  [LE-INFO-31#09:54:57] send pkt op:503, seq:193...   \n",
       "2018-08-31 09:54:58.201                   (surper.virtual.device mode 2)\\n   \n",
       "2018-08-31 09:54:58.206  [LE-INFO-31#09:54:57] recv pkt op:503, seq:193...   \n",
       "2018-08-31 09:54:58.212                                ((virtualmode 2))\\n   \n",
       "2018-08-31 09:54:58.214     (1, 1, rul-001-autolight-service:2, success)\\n   \n",
       "\n",
       "                          pid  pthreadid  \n",
       "datetime                                  \n",
       "2018-08-31 09:54:58.201  3620       2882  \n",
       "2018-08-31 09:54:58.201  3620       2882  \n",
       "2018-08-31 09:54:58.206  3620       2882  \n",
       "2018-08-31 09:54:58.212  3544       2882  \n",
       "2018-08-31 09:54:58.214  3544       2882  "
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# this method is wrong why: can not repeatly run this cell, 'datetime' already not string objec\n",
    "log_df['datetime'] = log_df['datetime'].apply(lambda x: datetime.strptime(x, '%m-%d %H:%M:%S.%f').replace(year=datetime.now().year))\n",
    "# log_df['datetime'] = pd.to_datetime(log_df['datetime'], format='%m-%d %H:%M:%S.%f')\n",
    "# log_df.sort_values(by='datetime', ascending=True)\n",
    "log_df.set_index('datetime', inplace=True)\n",
    "log_df.sort_index(inplace=True)\n",
    "log_df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>filename</th>\n",
       "      <th>function</th>\n",
       "      <th>level</th>\n",
       "      <th>line</th>\n",
       "      <th>message</th>\n",
       "      <th>pid</th>\n",
       "      <th>pthreadid</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>datetime</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2018-08-31 09:54:58.201</th>\n",
       "      <td>lecloud_interface.cpp</td>\n",
       "      <td>lecloud_print</td>\n",
       "      <td>4</td>\n",
       "      <td>24</td>\n",
       "      <td>[LE-INFO-31#09:54:57] send pkt op:503, seq:193...</td>\n",
       "      <td>3620</td>\n",
       "      <td>2882</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-08-31 09:54:58.201</th>\n",
       "      <td>HBCloudManager.cpp</td>\n",
       "      <td>propertyControl</td>\n",
       "      <td>4</td>\n",
       "      <td>33</td>\n",
       "      <td>(surper.virtual.device mode 2)</td>\n",
       "      <td>3620</td>\n",
       "      <td>2882</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-08-31 09:54:58.206</th>\n",
       "      <td>lecloud_interface.cpp</td>\n",
       "      <td>lecloud_print</td>\n",
       "      <td>4</td>\n",
       "      <td>24</td>\n",
       "      <td>[LE-INFO-31#09:54:57] recv pkt op:503, seq:193...</td>\n",
       "      <td>3620</td>\n",
       "      <td>2882</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-08-31 09:54:58.212</th>\n",
       "      <td>RuleEngineCore.cpp</td>\n",
       "      <td>assertRun</td>\n",
       "      <td>3</td>\n",
       "      <td>114</td>\n",
       "      <td>((virtualmode 2))</td>\n",
       "      <td>3544</td>\n",
       "      <td>2882</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-08-31 09:54:58.214</th>\n",
       "      <td>RuleEngineService.cpp</td>\n",
       "      <td>callMessagePush</td>\n",
       "      <td>3</td>\n",
       "      <td>336</td>\n",
       "      <td>(1, 1, rul-001-autolight-service:2, success)</td>\n",
       "      <td>3544</td>\n",
       "      <td>2882</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                      filename         function  level  line  \\\n",
       "datetime                                                                       \n",
       "2018-08-31 09:54:58.201  lecloud_interface.cpp    lecloud_print      4    24   \n",
       "2018-08-31 09:54:58.201     HBCloudManager.cpp  propertyControl      4    33   \n",
       "2018-08-31 09:54:58.206  lecloud_interface.cpp    lecloud_print      4    24   \n",
       "2018-08-31 09:54:58.212     RuleEngineCore.cpp        assertRun      3   114   \n",
       "2018-08-31 09:54:58.214  RuleEngineService.cpp  callMessagePush      3   336   \n",
       "\n",
       "                                                                   message  \\\n",
       "datetime                                                                     \n",
       "2018-08-31 09:54:58.201  [LE-INFO-31#09:54:57] send pkt op:503, seq:193...   \n",
       "2018-08-31 09:54:58.201                     (surper.virtual.device mode 2)   \n",
       "2018-08-31 09:54:58.206  [LE-INFO-31#09:54:57] recv pkt op:503, seq:193...   \n",
       "2018-08-31 09:54:58.212                                  ((virtualmode 2))   \n",
       "2018-08-31 09:54:58.214       (1, 1, rul-001-autolight-service:2, success)   \n",
       "\n",
       "                          pid  pthreadid  \n",
       "datetime                                  \n",
       "2018-08-31 09:54:58.201  3620       2882  \n",
       "2018-08-31 09:54:58.201  3620       2882  \n",
       "2018-08-31 09:54:58.206  3620       2882  \n",
       "2018-08-31 09:54:58.212  3544       2882  \n",
       "2018-08-31 09:54:58.214  3544       2882  "
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# trim/strip str of columns\n",
    "# %timeit log_df['message'] = log_df['message'].str.strip()\n",
    "log_df['message'] = log_df['message'].str.strip()\n",
    "# cost more time\n",
    "# %timeit log_df.applymap(lambda x : x.strip() if type(x) is str else x)\n",
    "# %timeit log_df['message'] = log_df['message'].apply(lambda x : x.strip() if type(x) is str else x)\n",
    "log_df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>filename</th>\n",
       "      <th>function</th>\n",
       "      <th>level</th>\n",
       "      <th>line</th>\n",
       "      <th>message</th>\n",
       "      <th>pid</th>\n",
       "      <th>pthreadid</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>datetime</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2018-08-31 09:54:58.201</th>\n",
       "      <td>HBCloudManager.cpp</td>\n",
       "      <td>propertyControl</td>\n",
       "      <td>4</td>\n",
       "      <td>33</td>\n",
       "      <td>(surper.virtual.device mode 2)</td>\n",
       "      <td>3620</td>\n",
       "      <td>2882</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-08-31 09:55:16.467</th>\n",
       "      <td>HBCloudManager.cpp</td>\n",
       "      <td>propertyControl</td>\n",
       "      <td>4</td>\n",
       "      <td>33</td>\n",
       "      <td>(surper.virtual.device mode 1)</td>\n",
       "      <td>3620</td>\n",
       "      <td>2882</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-08-31 09:56:13.787</th>\n",
       "      <td>HBCloudManager.cpp</td>\n",
       "      <td>propertyControl</td>\n",
       "      <td>4</td>\n",
       "      <td>33</td>\n",
       "      <td>(surper.virtual.device mode 9)</td>\n",
       "      <td>3620</td>\n",
       "      <td>2882</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-08-31 09:56:38.900</th>\n",
       "      <td>HBCloudManager.cpp</td>\n",
       "      <td>propertyControl</td>\n",
       "      <td>4</td>\n",
       "      <td>33</td>\n",
       "      <td>(surper.virtual.device mode 10)</td>\n",
       "      <td>3620</td>\n",
       "      <td>2882</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-08-31 09:56:49.771</th>\n",
       "      <td>HBCloudManager.cpp</td>\n",
       "      <td>propertyControl</td>\n",
       "      <td>4</td>\n",
       "      <td>33</td>\n",
       "      <td>(surper.virtual.device mode 9)</td>\n",
       "      <td>3620</td>\n",
       "      <td>2882</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                   filename         function  level  line  \\\n",
       "datetime                                                                    \n",
       "2018-08-31 09:54:58.201  HBCloudManager.cpp  propertyControl      4    33   \n",
       "2018-08-31 09:55:16.467  HBCloudManager.cpp  propertyControl      4    33   \n",
       "2018-08-31 09:56:13.787  HBCloudManager.cpp  propertyControl      4    33   \n",
       "2018-08-31 09:56:38.900  HBCloudManager.cpp  propertyControl      4    33   \n",
       "2018-08-31 09:56:49.771  HBCloudManager.cpp  propertyControl      4    33   \n",
       "\n",
       "                                                 message   pid  pthreadid  \n",
       "datetime                                                                   \n",
       "2018-08-31 09:54:58.201   (surper.virtual.device mode 2)  3620       2882  \n",
       "2018-08-31 09:55:16.467   (surper.virtual.device mode 1)  3620       2882  \n",
       "2018-08-31 09:56:13.787   (surper.virtual.device mode 9)  3620       2882  \n",
       "2018-08-31 09:56:38.900  (surper.virtual.device mode 10)  3620       2882  \n",
       "2018-08-31 09:56:49.771   (surper.virtual.device mode 9)  3620       2882  "
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# virtual mode search\n",
    "raw_vm = r'\\(surper.virtual.device mode (\\d+)\\)'\n",
    "vm_df = log_df[log_df['message'].str.match(raw_vm)]\n",
    "vm_df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class '_sre.SRE_Pattern'> <class '_sre.SRE_Match'> <class 'str'> 1\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>filename</th>\n",
       "      <th>function</th>\n",
       "      <th>level</th>\n",
       "      <th>line</th>\n",
       "      <th>message</th>\n",
       "      <th>pid</th>\n",
       "      <th>pthreadid</th>\n",
       "      <th>inplace</th>\n",
       "      <th>vm</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>datetime</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2018-08-31 09:54:58.201</th>\n",
       "      <td>HBCloudManager.cpp</td>\n",
       "      <td>propertyControl</td>\n",
       "      <td>4</td>\n",
       "      <td>33</td>\n",
       "      <td>(surper.virtual.device mode 2)</td>\n",
       "      <td>3620</td>\n",
       "      <td>2882</td>\n",
       "      <td>True</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-08-31 09:55:16.467</th>\n",
       "      <td>HBCloudManager.cpp</td>\n",
       "      <td>propertyControl</td>\n",
       "      <td>4</td>\n",
       "      <td>33</td>\n",
       "      <td>(surper.virtual.device mode 1)</td>\n",
       "      <td>3620</td>\n",
       "      <td>2882</td>\n",
       "      <td>True</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-08-31 09:56:13.787</th>\n",
       "      <td>HBCloudManager.cpp</td>\n",
       "      <td>propertyControl</td>\n",
       "      <td>4</td>\n",
       "      <td>33</td>\n",
       "      <td>(surper.virtual.device mode 9)</td>\n",
       "      <td>3620</td>\n",
       "      <td>2882</td>\n",
       "      <td>True</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-08-31 09:56:38.900</th>\n",
       "      <td>HBCloudManager.cpp</td>\n",
       "      <td>propertyControl</td>\n",
       "      <td>4</td>\n",
       "      <td>33</td>\n",
       "      <td>(surper.virtual.device mode 10)</td>\n",
       "      <td>3620</td>\n",
       "      <td>2882</td>\n",
       "      <td>True</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-08-31 09:56:49.771</th>\n",
       "      <td>HBCloudManager.cpp</td>\n",
       "      <td>propertyControl</td>\n",
       "      <td>4</td>\n",
       "      <td>33</td>\n",
       "      <td>(surper.virtual.device mode 9)</td>\n",
       "      <td>3620</td>\n",
       "      <td>2882</td>\n",
       "      <td>True</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                   filename         function  level  line  \\\n",
       "datetime                                                                    \n",
       "2018-08-31 09:54:58.201  HBCloudManager.cpp  propertyControl      4    33   \n",
       "2018-08-31 09:55:16.467  HBCloudManager.cpp  propertyControl      4    33   \n",
       "2018-08-31 09:56:13.787  HBCloudManager.cpp  propertyControl      4    33   \n",
       "2018-08-31 09:56:38.900  HBCloudManager.cpp  propertyControl      4    33   \n",
       "2018-08-31 09:56:49.771  HBCloudManager.cpp  propertyControl      4    33   \n",
       "\n",
       "                                                 message   pid  pthreadid  \\\n",
       "datetime                                                                    \n",
       "2018-08-31 09:54:58.201   (surper.virtual.device mode 2)  3620       2882   \n",
       "2018-08-31 09:55:16.467   (surper.virtual.device mode 1)  3620       2882   \n",
       "2018-08-31 09:56:13.787   (surper.virtual.device mode 9)  3620       2882   \n",
       "2018-08-31 09:56:38.900  (surper.virtual.device mode 10)  3620       2882   \n",
       "2018-08-31 09:56:49.771   (surper.virtual.device mode 9)  3620       2882   \n",
       "\n",
       "                         inplace  vm  \n",
       "datetime                              \n",
       "2018-08-31 09:54:58.201     True   2  \n",
       "2018-08-31 09:55:16.467     True   1  \n",
       "2018-08-31 09:56:13.787     True   9  \n",
       "2018-08-31 09:56:38.900     True  10  \n",
       "2018-08-31 09:56:49.771     True   9  "
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "vm_re = re.compile(raw_vm)\n",
    "\n",
    "# test re match\n",
    "match = vm_re.match('(surper.virtual.device mode 1)')\n",
    "print(type(vm_re), type(match), type(match.group(0)), int(match.group(1)))\n",
    "\n",
    "# with warning: SettingWitchCopyWarning\n",
    "# vm_df['vm'] = vm_df['message'].apply(lambda x : int(vm_re.match(x).group(1)))\n",
    "# inplace is not work\n",
    "vm_df = vm_df.assign(vm=vm_df['message'].apply(lambda x : int(vm_re.match(x).group(1))), inplace=True)\n",
    "vm_df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(Timestamp('2018-08-31 10:05:05.569000'),\n",
       " Timestamp('2018-08-31 09:54:58.201000'),\n",
       " 10,\n",
       " 1)"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "vm_df.index.max(), vm_df.index[0], vm_df['vm'].max(), vm_df.vm.min()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAeIAAADZCAYAAAD8IzN5AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMi4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvhp/UCwAAEwNJREFUeJzt3X9s1GWCx/HPc+2UzhZxULGhc7KgYPEPidivEKDSodlYKlcppyEaCPH0LN7tuccfNtnGrHK5TdxNb1eJ665WiK7BeHvs1gFZ1pKAEz03ro6p2SZ65fSUjVM2/Fi7LDLQWp77A0ooTOnszHz7fNt5vxITfHz6PJ/vtJ2P3+98mTHWWgEAADf+xnUAAACKGUUMAIBDFDEAAA5RxAAAOEQRAwDgEEUMAIBDFDEAAA5RxAAAOEQRAwDgUOl4bLJy5Ur7xhtvjMdWAAAEhclm0ricER89enQ8tgEAYMLh0jQAAA5RxAAAOEQRAwDgEEUMAIBD43LXNPwR706pvatXff1pVUXCam2oVvPCqOtYviimYwVQXMY8IzbGlBtjHjHGfG6Muf/c2CJjzFvGmHeMMf/he0pcIt6dUltnj1L9aVlJqf602jp7FO9OuY5WcMV0rACKTzaXpislpSW9csFYh6T11tplkm4xxiz1IxxG197Vq/Tg0Iix9OCQ2rt6HSXyTzEdK4DiM+alaWvtQUlbjTGbJckYM13SoKQTxphtkqZKuk3Sby/8OmNMi6RWSZHKykolEonCJi9yqf70qOOT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iK/dtGmTNm3apFOnTmn58uVqaGhQdXW1PvnkE0lSZ2enHnvsMb366quByXf8+HF5nqfnn39eR44c0aJFi3TXXXcFJl91dbUk6dlnn9W9996radOm5ZzNr4xXXXWVvvrqKzU2Nqqvr0/vv/++Fi1aFJh8GzZs0MaNG7VixQrNmDFjxBlKIfT19Wn9+vV68skn9dZbb+nMmTOj5htt7sXHHLR8fipUvng8ru7ubv3qV78KXL5Vq1Zp1apV2rNnjx5++GHt2rUrMPk6OjpUX1+vG2+8sWCZCplPUkE75HIC8RpxTU2NFi5cqMcff1zJZFI33XSTVq9erbffflsvv/yyIpGI6urqzs9fu3at3nzzzUvWKSkpkSRdccUVI8attecvQQQl37x583Tw4EFJUllZWV5P0n49fsePH9fWrVv1yCOP5JzNz4y7du3SggUL1NLSoo6ODr3wwguByldRUaHt27frzTff1NKlS7Vu3bqc811s+vTpmjp1qrZu3aoFCxZoz549Wrp0acZ8o83NdMxByuenQuXbtm2bduzYoR07duT9EpMf+YZFIhGFw+FA5Xv99dcVj8cVi8X04Ycf6t57783rdfZC57tQvh0ylkCcEd93333au3ev6urqVFpaqueee04//OEPtW/fPpWXl+upp57S1KlTz8//+OOPR7xR95NPPqm9e/fKGKNHH31UVVVVOnz4sO6++25NmTJF1157rZ599tlA5auqqtL8+fO1dOlShUIhbdmyJVD5JOlHP/qRHnjggRFfG6SMd955p1555RXFYjF9/fXX+t73vheofH/84x+1bt06WWtVX1+vtra2nPN98cUXam5uVl9fn6ZMmaL9+/frZz/7mdasWaNQKKQ77rhDt91226j5Ms295ZZbLjnmIOXLtObLL78cmHzJZFItLS1atmyZ7rjjDpWVlWnv3r2ByffZZ5/p/vvvV3l5uaZNm6ann346p2x+5du9e/f5/x6LxfTSSy9p9uzZgclXyA4ZC++sBQCAP3hnLQAAgo4iBgDAIYoYAACHKGIAAByiiAEAcIgiBgDAIYoYAACHKGIAAByiiAEAcIgiBgDAIYoYAACHAvGhD0CxiHen1N7Vq77+tKoiYbU2VKt5YdR1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KIAQBwiCIGAMAhihgAAIcm1HtN5yLeneKDIgAAgTWpizjenVJbZ4/Sg0OSpFR/Wm2dPZJEGQMAAmFSX5pu7+o9X8LD0oNDau/qdZQIAICRfD0jNsY0SWqKRqNKJBJ+bpVRqj896riLPACA4hGLxbKaZ6y1/iaR5HmeTSaTvu9zsWU/2J+xjKORsN75bv245wEAFBWTzaRJfWm6taFa4VDJiLFwqEStDdWOEgEAMNKkvllr+IYs7poGAATVpC5i6WwZU7wAgKCa1JemAQAIOooYAACHKGIAAByiiAEAcGhc/h6xMeYNa+1K3zcCAGCCGZciBgAAmXFpGgAAhyhiAAAcoogBAHCIIgYAwCGKGAAAhyhiAAAcoogBAHCIIgYAwCGKGAAAh/4fAmLyh4wkkKMAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 576x288 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "fig = plt.figure(figsize=(8,4))\n",
    "ax = fig.add_subplot(111)\n",
    "\n",
    "# delta_x = (vm_df.index[-1]-vm_df.index[0])/vm_df.index.size\n",
    "# delta_y = (vm_df.vm[-1]-vm_df.vm[0])/vm_df.vm.size\n",
    "# ax.set_ylabel('mode')\n",
    "# ax.set_xlim([vm_df.index.min()-delta_x, vm_df.index.max()+delta_x])\n",
    "# ax.set_ylim([vm_df.vm.min()-delta_y, vm_df.vm.max()+delta_y])\n",
    "\n",
    "ax.spines['right'].set_color('none')\n",
    "ax.spines['top'].set_color('none')\n",
    "ax.spines['bottom'].set_position(('data', 5.5))\n",
    "\n",
    "# format the ticks\n",
    "fmt = mdates.DateFormatter('%H:%M')\n",
    "ax.xaxis.set_major_locator(mdates.MinuteLocator())\n",
    "ax.xaxis.set_major_formatter(fmt)\n",
    "ax.xaxis.set_minor_locator(mdates.MinuteLocator())\n",
    "\n",
    "ax.yaxis.set_major_locator(MultipleLocator(2))\n",
    "ax.yaxis.set_minor_locator(MultipleLocator(1))\n",
    "\n",
    "# auto rotate the xaxis label\n",
    "fig.autofmt_xdate()\n",
    "ax.plot_date(x=vm_df.index, y=vm_df.vm, xdate=True)\n",
    "ax.grid(True, which='minor', axis='y')"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.4.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
